var productID=null;//商品ID
var productName="";//商品名称
var pro_webtyp=0;//页面类型(0普通商品页面,1抢购页面,2弹出页面)
var loadgoodscommentno=false;//是否已加载了评论信息
var loadgoodsadvisoryno=false;//是否已加载了咨询信息
$(function(){
	if($("#main5").size()<=0){$("#menu5").remove();}else{$("#menu5").show();}
	loadgoodscommentinfo();
	loadgoodsadvisory();
	if($("#btn_goodscomment")[0]){
		$("#btn_goodscomment").click(function(){
			var options={
				url:lodo_web_path+"savecomment.asp?bn="+Math.random(),
				dataType:"json",
				success:gcomment_handle,
				beforeSubmit:checkform
				};
			$("#UpComment").ajaxSubmit(options);
			return false;
		});
	}
	if($("#btn_goodadvisory")[0]){
		$("#btn_goodadvisory").click(function(){
			var options={
				dataType:"json",
				success:function(data){
					removeloadding("btn_goodadvisory");
					$("#btn_goodadvisory").show();
					if(data.errno){alert(data.msg);return false;}
					if(data.gotono){location.href=data.gotourl};
					$("#UpAdvisory #advisory_email,#UpAdvisory #advisory_Contents,#UpAdvisory #Advisory_Code").val("");
					$("#Advisory_Code_img img.code:first").click();
					if(data.ch){
						alert(data.msg);
						if(data.loadno){
							$(".goods_advisory_totalNum").html(data.totalNum);
							loadgoodsadvisoryno=false;
							loadgoodsadvisory();
						}
					}
				}
			};
			$("#btn_goodadvisory").hide();
			loadding("btn_goodadvisory",lodo_lang_js.pro.loaddingTxt);
			$("#UpAdvisory").ajaxSubmit(options);
			return false;
		});
	}
})

//加载商品点评
function loadgoodscommentinfo(){
	if(loadgoodscommentno){return false;}
	if($("#goods_comment_list")[0]){
		$("#goods_comment_list").html("<img src='images/loading3.gif'>"+lodo_lang_js.pro.loadingData);
		$.get(lodo_web_path+"ajax_data.asp?action=goodscommentinfo&pro_webtyp="+pro_webtyp+"&gid="+productID+"&bn="+Math.random(),function(data){
		   $("#goods_comment_list").html(data);
		   loadgoodscommentno=true;
	   })
	}
}

//加载商品咨询
function loadgoodsadvisory(){
	if(loadgoodsadvisoryno){return false;}
	if($("#goods_advisory_list")[0]){
		$("#goods_advisory_list").html("<img src='images/loading3.gif'>"+lodo_lang_js.pro.loadingData);
		$.get(lodo_web_path+"SaveAdvisory.asp?act=loadinfo&pro_webtyp="+pro_webtyp+"&gid="+productID+"&bn="+Math.random(),function(data){
		   $("#goods_advisory_list").html(data);
		   loadgoodsadvisoryno=true;
	   })
	}
}


function checkform(formdata,jqForm,options){
	if($("#UpComment #CName").val()==""){
		alert(lodo_lang_js.pro.check_name);
		$("#UpComment #CName").focus();
		return false;
	}
	if($("#UpComment #CEmail").val()!=""&&!checkemail($("#UpComment #CEmail").val())){
		alert(lodo_lang_js.pro.check_cmail);
		$("#UpComment #CEmail").focus();
		return false;
	}
	if($("#UpComment #Cyode1").val()==""){
		alert(lodo_lang_js.pro.check_code);
		$("#UpComment #Cyode1").focus();
		return false;
	}
	if($("#UpComment #Contents").val()==""){
		alert(lodo_lang_js.pro.check_message);
		$("#UpComment #Contents").focus();
		return false;
	}
	$("#btn_goodscomment").hide();
	loadding("btn_goodscomment",lodo_lang_js.pro.loaddingTxt);
}

function gcomment_handle(data){
		removeloadding("btn_goodscomment");
		$("#btn_goodscomment").show();
		if(data.errno){alert(data.msg);if(data.gotono){location.href=data.gotourl};return false;}
		$("#UpComment #CName,#UpComment #CEmail,#UpComment #Cyode1,#UpComment #Contents").val("");
		$("#Cyode1_img img.code:first").click();
		if(data.geno==1){
			alert(lodo_lang_js.pro.plsh_msg);
		}else{
			$(".goods_comment_totalNum").html(data.totalNum);
			alert(lodo_lang_js.pro.pl_msg);
			loadgoodscommentno=false;
			loadgoodscommentinfo();
		}
		return false;
}

/*function chkDozen(e,lv,lvtype){
	if(!isDigit(e.value)){
		alert("购买数量只能由整数组成！");
		e.value=lv;
		e.focus();
		return false;
	}
	var buysum=e.value;
	var lodo_goods_quantity=$("#ark_buy_maxCount").val();
	if(buysum>eval(lodo_goods_quantity)&&(lodo_goods_quantity!="-1")){alert("此商品现在只有"+lodo_goods_quantity+"件");e.value=lv;e.focus();return false;}
	if(lvtype==0){
	if ( (e.value<=0 || (e.value % lv) != 0)){
			alert("购买数量只能是"+lv+"的整数倍！");
			e.value=lv;
			e.focus();
			return false;
		}
	}else{
		if(e.value<lv){
			alert("此商品最低购买量不能少于"+lv+"件");
			e.value=lv;
			e.focus();
			return false;
		}
	}
}*/

/*function pro_post_cart2(gid,oaid,buyqn){
	var option={
		action:function(){
			var url=lodo_web_path+"cart2.asp?act=fastbuy&bn="+Math.random();
			$("#ark_cartForm").attr("action",url).submit();
		}
	}
	$.getJSON(lodo_web_path+"ajax_data.asp?action=getuserlogininfo&gid="+gid+"&oaid="+oaid+"&buyqn="+buyqn+"",function(data){
		if(data.errno){alert(data.msg);return false;}
		if(data.gotono){location.href=data.gotourl};
		if(data.logno){
			$loginFrame({
				type:"func",
				check: false,
				checkReady:false,
				model: false,
				title:"登录后购买",
				gotourl:data.gotourl,
				action:option.action
			});
		}else{
			option.action();
		}
	})
}*/